package com.lmq.chapter02;

import java.util.Random;

public class MathOps {
    public static void main(String[] args) {
        // create a seeded random number generator:
        Random rand = new Random();
        int i,j,k;
        // Choose value from 1 to 100
        j = rand.nextInt(100) + 1;
        System.out.println("j : " + j);
        k = rand.nextInt(100) + 1;
        System.out.println("k : " + k);
        i = j - k;
        System.out.println("j - k : " + i);

        // underscores in Literals
        double d = 341_435_936.445_667;
        System.out.println(d);
        int bin = 0b0010_1111_1010_1111_1010_1111_1010_1111;
        System.out.println(Integer.toBinaryString(bin));
        System.out.printf("%x%n", bin); // [1]
        long hex = 0x7f_e9_b7_aa;
        System.out.printf("%x%n", hex);// %x 16进制输出 "\n"

        // Exponential Notation

        // Uppercase and lowercase 'e' are the same:
        float expFloat = 1.39e-43f;
        expFloat = 1.39E-43f;
        System.out.println(expFloat);
        double expDouble = 47e47d; // 'd' is optional
        double expDouble2 = 47e47; // Automatically double
        System.out.println(expDouble);
        long n3 = 200;
        float f4 = 1e-43f;

        int iShift = 2;
        int iShift2 = -16;
        System.out.println(Integer.toBinaryString(iShift2));
        iShift <<= 2;
        System.out.println(Integer.toBinaryString(iShift));
        int iRShift = iShift2 >>=2;
        System.out.println(Integer.toBinaryString(iRShift));
        System.out.println(Integer.toBinaryString(iShift2));

        System.out.println("********************************");
        byte b = -1;
        System.out.println(Integer.toBinaryString(b));
        b >>>= 10;
        System.out.println(Integer.toBinaryString(b));
        b = -1;
        System.out.println(Integer.toBinaryString(b));
        System.out.println(Integer.toBinaryString(b>>>10));




    }
}
